<!-- 毛坯仓收货 -->
<template>
    <div class="search-form isheader" v-if="headerShow">
        <div>
            <a-form size="small" :model="pageData" layout="inline">
                <a-form-item label="来源单号">
                    <a-input allow-clear :style="{ width: '200px' }" class="bacClass" v-model="pageData.sourceCode" />
                </a-form-item>
                <a-form-item label="客户名称">
                    <a-input allow-clear :style="{ width: '200px' }" class="bacClass" v-model="pageData.customName" />
                </a-form-item>
                <a-form-item label="开单日期">
                    <a-date-picker  popup-container="html"  class="bacClass" v-model="pageData.dateStart" />
                </a-form-item>
                <a-form-item label="至"><a-date-picker  popup-container="html"  class="bacClass" v-model="pageData.dateEnd" />
                </a-form-item>
            </a-form>
        </div>
        <div style="text-align: end;">
            <Toolbar :items="toolbarList" @reders="addHandler" @select="selectHandler" @del="deleteHandler"
                @dyBoufei="counters" @audit="audits">
            </Toolbar>
        </div>
    </div>

    <div class="my-divisders">
        <a-divider orientation="center">
            <icon-double-up v-if="headerShow" @click="headerShow = false" :strokeWidth="2" :size="18" />
            <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
    </div>

    <!-- </template> -->
    <!-- <template #pageTabel> -->
    <div class="gang"></div>
    <div :style="{ height: '76vh', padding: '10px' }">
        <a-tabs   :lazy-load="true" :justify="true" :default-active-key="tabsKeys" @change="tabsChanges">
            <a-tab-pane title="车间退库" :key="5">
                <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple" @grid-ready="gridReady5"
                    style="height:94%" :defaultColDef="defaultColDef5" class='ag-theme-alpine' :rowData="tableDataList5"
                    :columnDefs="tc5" :localeText="localeText1"></AgGridVuesCopys>
                <paginationCopys :page-size-options="pagingList1" :total="total5" show-total show-jumper show-page-size
                    @change="PageSize" @page-size-change="change" style="justify-content: center"
                    :page-size="pagination5.pageSize" :current="pagination5.page" />
            </a-tab-pane>
            <a-tab-pane title="未审核" :key="3">
                <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple" @grid-ready="gridReady3"
                    style="height:94%" :defaultColDef="defaultColDef3" class='ag-theme-alpine' :rowData="tableDataList3"
                    :columnDefs="tc3" :localeText="localeText1"></AgGridVuesCopys>
                <paginationCopys :page-size-options="pagingList1" :total="total3" show-total show-jumper show-page-size
                    @change="PageSize" @page-size-change="change" style="justify-content: center"
                    :page-size="pagination3.pageSize" :current="pagination3.page" />
            </a-tab-pane>
            <a-tab-pane title="已审核" :key="4">
                <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple" @grid-ready="gridReady4"
                    style="height:94%" :defaultColDef="defaultColDef4" class='ag-theme-alpine' :rowData="tableDataList4"
                    :columnDefs="tc4" :localeText="localeText1"></AgGridVuesCopys>
                <paginationCopys :page-size-options="pagingList1" :total="total4" show-total show-jumper show-page-size
                    @change="PageSize" @page-size-change="change" style="justify-content: center"
                    :page-size="pagination4.pageSize" :current="pagination4.page" />
            </a-tab-pane>
        </a-tabs>
        <!-- </template> -->
    </div>
    <a-drawer :drawer-style="{ 'zIndex': 9999 }" :mask-closable="false" height="80%" :visible="pageData.showAdd8"
        unmountOnClose @ok="sideOk" @cancel="pageData.showAdd8 = false" cancel-text='关闭' ok-text='保存' placement="bottom">
        <template #title>
            {{ pageData.sideTitle }}
        </template>
        <div style="min-width:800px;">
            <div>
                <a-row :gutter="16">
                    <a-col :span="4">
                        <a-form-item label="开单日期">
                            <a-date-picker  popup-container="html"  class="bacClass" v-model="objectOP.stocklnDate" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="4">
                        <a-form-item label="计件日期">
                            <a-date-picker  popup-container="html"  class="bacClass" v-model="objectOP.reckonPieceDate" />
                        </a-form-item>
                    </a-col>
                    <a-col :span="4" v-if="pageData.sideTitle == '新增车间退库' || pageData.sideTitle == '修改入库单'">
                        <a-form-item label="仓库名称">
                            <a-select popup-container="html"  disabled class="bacClass" :loading="loading" :allowClear="true"
                                v-model="objectOP.warehouseName" :filter-option="false" allow-search>
                                <a-option v-for="item in pageData.nameList" :value="item['warehouseName']">{{
                                    item['warehouseName']
                                }}</a-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :span="4">
                        <a-form-item label="业务员">
                            <a-select popup-container="html"  class="bacClass" :loading="loading" :allowClear="true" @search="handleSearch1"
                                v-model="objectOP.salesman" :filter-option="false" allow-search @focus="focusSel1">
                                <a-option v-for="item in pageData.nameList1" :value="item['name']">{{
                                    item['name']
                                }}</a-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :span="4">
                        <a-form-item label="入库类型">
                            <a-input v-model="objectOP.stockInTypeName" disabled class="bacClass"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="4">
                        <a-form-item label="客户订单号">
                            <a-input disabled class="bacClass" v-model="objectOP.customOrderCode"></a-input>
                        </a-form-item>
                    </a-col>
                </a-row>
                <a-row :gutter="16">
                    <a-col :span="4">
                        <a-form-item label="客户名称">
                            <a-input disabled class="bacClass" v-model="objectOP.customName"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="4">
                        <a-form-item label="送货车号">
                            <a-input disabled class="bacClass" v-model="objectOP.carPlate"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="4">
                        <a-form-item label="送货工">
                            <a-input class="bacClass" v-model="objectOP.deliveryPerson"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="4">
                        <a-form-item label="送货单位">
                            <a-input disabled class="bacClass" v-model="objectOP.deliveryDepartmentName"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="4">
                        <a-form-item label="加工单位">
                            <a-input disabled class="bacClass" v-model="objectOP.processDepartment"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="4">
                        <a-form-item label="搬运方式">
                            <a-select popup-container="html"  class="bacClass" :loading="loading" :allowClear="true"
                                v-model="objectOP.carryTypeName" :filter-option="false" allow-search @focus="focusSel4"
                                @change="change4">
                                <a-option v-for="item in pageData.nameList4" :value="item['carryTypeName']">{{
                                    item['carryTypeName']
                                }}</a-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                </a-row>
                <a-row :gutter="16">
                    <a-col :span="4">
                        <a-form-item label="重量">
                            <a-input disabled class="bacClass" v-model="objectOP.weight"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="4">
                        <a-form-item label="匹数">
                            <a-input disabled class="bacClass" v-model="objectOP.horseNum"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="4">
                        <a-form-item label="计价方式">
                            <a-select popup-container="html"  class="bacClass" :loading="loading" :allowClear="true"
                                v-model="objectOP.reckonPieceTypeName" :filter-option="false" allow-search>
                                <a-option>重量</a-option>
                                <a-option>长度</a-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :span="4">
                        <a-form-item label="备注">
                            <a-input class="bacClass" v-model="objectOP.remark"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="4">
                        <a-form-item label="收货单号">
                            <a-input disabled class="bacClass" v-model="objectOP.deliveryCode"></a-input>
                        </a-form-item>
                    </a-col>
                </a-row>
            </div>
        </div>
        <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" v-if="pageData.sideTitle == '修改入库单'" rowSelection="multiple"
            @grid-ready="gridReady3_2" style="height:75%" :defaultColDef3_2="defaultColDef3_2" class='ag-theme-alpine'
            :rowData="tableDataList3_2" :columnDefs="dc3" :localeText="localeText1"></AgGridVuesCopys>
        <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" v-else rowSelection="multiple" @grid-ready="gridReady5_1"
            style="height:75%" :defaultColDef="defaultColDef5_1" class='ag-theme-alpine' :rowData="tableDataList5_1"
            :columnDefs="dc5" :localeText="localeText1"></AgGridVuesCopys>
        <!-- </div> -->

    </a-drawer>
</template>
<script setup lang="ts">
import {
    useTable,
    useRowKey,
    useTableColumn,
    usePagination,
    useRowSelection,
} from "@/hooks/table";
import { post, get } from "@/api/http"
import { localeText } from '@/api/aggridZw'

import Toolbar from "@/components/Toolbar.vue"
import { Message, Modal } from "@arco-design/web-vue"
import CorporateSectorCascader from '@/components/corporateSectorCascader1/index.vue'
import { FormInstance } from "@arco-design/web-vue/es/form";
import { pagingList } from "@/api/paging";
import dayjs from 'dayjs'
import printJS from 'print-js'
import { ref, reactive, onMounted, onActivated, onUnmounted, nextTick } from "vue";
// const toolbarList: any = ref(['查询', '入库', '删除', '审核', '反审', '打印'])
const toolbarList: any = ref(['查询', '入库'])
let isIDs: any = ref(5);
onMounted(() => {
    // 第一个页面需要在刚进入就调用一次  切换tap时也需要调用
    // doRefresh();
    // selCxAll({});
    // 切换tap到本页面执行的方法
    // emitter.on("DevelopSampleRegistrationListDemo", () => {
    //     // selCxAll({});
    //     doRefresh();
    // });
    pageData.rHeight = document.getElementsByClassName("main-section")[0]?.clientHeight
    //弹出层的高
    if (pageData.rHeight !== undefined) {
        pageData.rHeight = pageData.rHeight - 100;
    }
});

function PageSize(val: any) {
    if (isIDs.value == 3) {
        pagination3.page = val
        doRefresh3();
    } else if (isIDs.value == 4) {
        pagination4.page = val
        doRefresh4();
    } else if (isIDs.value == 5) {
        pagination5.page = val
        doRefresh5();
    }
}

function change(val: any) {
    if (isIDs.value == 3) {
        pagination3.pageSize = val
        doRefresh3();
    } else if (isIDs.value == 4) {
        pagination4.pageSize = val
        doRefresh4();
    } else if (isIDs.value == 5) {
        pagination5.pageSize = val
        doRefresh5();
    }
}


const headerShow = ref(true)

const tableDataList1 = ref([])
const tableDataList1_2 = ref([])
const tableDataList3_2 = ref([])
const tableDataList3 = ref([])
const tableDataList4 = ref([])
const tableDataList5 = ref([])
const tableDataList5_1 = ref([])






const gridOption3_2 = ref()
const gridReady3_2 = (params: any) => {
    gridOption3_2.value = params.api
}
const gridOption3 = ref()
const gridReady3 = (params: any) => {
    gridOption3.value = params.api
}
const gridOption4 = ref()
const gridReady4 = (params: any) => {
    gridOption4.value = params.api
}
const gridOption5 = ref()
const gridReady5 = (params: any) => {
    gridOption5.value = params.api
}
const gridOption5_1 = ref()
const gridReady5_1 = (params: any) => {
    gridOption5_1.value = params.api
}



const defaultColDef3_2 = {
    sortable: true,
    resizable: true,
    filter: true,
}
const defaultColDef3 = {
    sortable: true,
    resizable: true,
    filter: true,
}
const defaultColDef4 = {
    sortable: true,
    resizable: true,
    filter: true,
}
const defaultColDef5 = {
    sortable: true,
    resizable: true,
    filter: true,
}
const defaultColDef5_1 = {
    sortable: true,
    resizable: true,
    filter: true,
}

const localeText1: any = ref(localeText)


const dc3 = [
    {
        showRowGroup: 'hide_def',
        "headerName": "",
        "checkboxSelection": true,
        "headerCheckboxSelection": true,
        "pinned": "left",
        "width": 50,
        resizable: false,
        filter: false,
        sortable: false,
        minWidth: 50,
        maxWidth: 50,
        lockPosition: "left",
    },
    {
        headerName: '计划单号',
        field: 'planOrderCode',
        width: 150,
    },
    {
        headerName: '织造序号',
        field: 'weaveCode',
        width: 150
    },
    {
        headerName: '品名',
        field: 'brandName',
        width: 150
    },
    {
        headerName: '色号',
        field: 'colorCode',
        width: 150
    },
    {
        headerName: '色称',
        field: 'colorName',
        width: 150
    },
    {
        headerName: '坯布编号',
        field: 'greyCode',
        width: 150
    },
    {
        headerName: '坯布名称',
        field: 'greyName',
        width: 150,
    },
    {
        headerName: '匹号',
        field: 'horseNo',
        width: 150
    },
    {
        headerName: '单位',
        field: 'unit',
        width: 150
    },
    {
        headerName: '等级',
        field: 'grade',
        width: 150
    },
    {
        headerName: '条码号',
        field: 'clothfiyCode',
        width: 150
    },
    {
        headerName: '尺寸',
        field: 'inch',
        width: 150
    },
    {
        headerName: '重量',
        field: 'weight',
        width: 150
    },
    {
        headerName: '单价',
        field: 'price',
        width: 150,
    },
    {
        headerName: '门幅',
        field: 'width',
        width: 150
    },
    {
        headerName: '金额',
        field: 'amount',
        width: 150
    },
    {
        headerName: '克重',
        field: 'gramWeight',
        width: 150
    },
    {
        headerName: '区域',
        field: 'areaName',
        width: 150
    },
    {
        headerName: '纱批',
        field: 'yarnBatch',
        width: 150
    },
    {
        headerName: '流转卡号',
        field: 'circulatCard',
        width: 150
    },
    {
        headerName: '布号',
        field: 'clothCode',
        width: 150
    },
    {
        headerName: '备注',
        field: 'remark',
        width: 150
    },
    {
        headerName: '库位',
        field: 'storageId',
        dataIndex: 'storageId',
        pinned: 'right',
        width: 200,
        cellRenderer: {
            template: `
        
            <a-select popup-container="html"  class="bacClass" :loading="loading" :allowClear="true" @search="handleSearchKW" :filter-option="false" allow-search @focus="focusSelKW" v-model="mydata.storageId" @change="changes(ress)">
                                    <a-option :value="mydata.storageId">{{ mydata.storageName}}</a-option>
                                    <a-option v-for="item in pageData.nameListKW" :value="item['id']">{{
                                        item['storageName']
                                    }}</a-option>
                                </a-select>
            `,
            setup(props: any) {
                // console.log(props.params.data, '11111111111');

                const mydata = ref(props.params.data);


                const res = reactive<{
                    storageId: any,
                }>({
                    storageId: null,
                })
                const pageData = reactive<{
                    nameListKW: any[],
                }>({
                    nameListKW: [],
                });
                // 库位下拉框事件
                const focusSelKW = () => {
                    selCxAllKW({ "warehouseId": objectOP.warehouseId, storageName: "" })
                    // console.log(pageData.nameListKW)
                }
                const optionsKW = ref<any>(pageData.nameListKW);
                const loadingKW = ref(false);
                const handleSearchKW = (value: any) => {
                    if (value) {
                        const ob = { "warehouseId": objectOP.warehouseId, storageName: value }
                        loadingKW.value = true;
                        selCxAllKW(ob);
                        optionsKW.value = pageData.nameListKW;
                        loadingKW.value = false;
                    } else {
                        optionsKW.value = []
                    }
                };
                function selCxAllKW(val: any) {
                    if (objectOP.warehouseId == '') {
                        Message.error({
                            content: "请先选择上方仓库名称！",
                            duration: 5000,
                        });
                    } else {
                        post({
                            url: "/dwWms/Storage/getFieldValue",
                            data: val
                        }).then(({ data, code }: any) => {
                            if (code === 200) {
                                pageData.nameListKW = data;


                            } else {
                                Message.error({
                                    content: "查询失败！",
                                    duration: 5000,
                                });
                            }
                        });
                    }

                }
                const changes = (ress: any) => {
                    props.params.data.storageId = res.storageId
                    post({
                        url: "/dwWms/Storage/getStorageByPara",
                        data: { id: res.storageId }
                    }).then(({ data, code }: any) => {
                        if (code === 200) {
                            props.params.data.areaId = data[0].areaId;
                        } else {
                            Message.error({
                                content: "查询失败！",
                                duration: 5000,
                            });
                        }

                    });
                }

                return {
                    changes,
                    res,
                    pageData,
                    reactive,
                    selCxAllKW,
                    focusSelKW,
                    handleSearchKW,
                    mydata
                }
            }
        }
    },
    {
        headerName: '托盘编号',
        // field: 'shelveId',
        // dataIndex: 'shelveId',
        field: 'shelveCode',
        dataIndex: 'shelveCode',
        pinned: 'right',
        width: 200,

    }

];
const tc3 = [
    {
        showRowGroup: 'hide_def',
        "headerName": "",
        "checkboxSelection": true,
        "headerCheckboxSelection": true,
        "pinned": "left",
        "width": 50,
        resizable: false,
        filter: false,
        sortable: false,
        minWidth: 50,
        maxWidth: 50,
        lockPosition: "left",
    },
    {
        headerName: '入库单号',
        field: 'stockInCode',
        width: 150,
    },
    {
        headerName: '入库日期',
        field: 'stockInDate',
        width: 150
    },
    {
        headerName: '收料单号',
        field: 'deliveryCode',
        width: 150
    },
    {
        headerName: '计件日期',
        field: 'reckonPieceDate',
        width: 150
    },
    {
        headerName: '公司',
        field: 'companyName',
        width: 150
    },
    {
        headerName: '仓库',
        field: 'warehouseName',
        width: 150,
    },
    {
        headerName: '业务员',
        field: 'salesman',
        width: 150
    },
    {
        headerName: '入库类型',
        field: 'stockInTypeName',
        width: 150
    },
    {
        headerName: '送货车号',
        field: 'carPlate',
        width: 150
    },
    {
        headerName: '送货工',
        field: 'deliveryPerson',
        width: 150
    },
    {
        headerName: '送货单位',
        field: 'deliveryDepartmentName',
        width: 150,
    },
    {
        headerName: '加工单位',
        field: 'processDepartment',
        width: 150
    },
    {
        headerName: '搬运方式',
        field: 'carryTypeName',
        width: 150
    },
    {
        headerName: '计件方式',
        field: 'reckonPieceTypeName',
        width: 150
    },
    {
        headerName: '备注',
        field: 'remark',
        width: 150
    },
    {
        headerName: '状态',
        field: 'infoState',
        pinned: 'right',
        width: 150,
        cellRenderer: {
            template: `
                <a-space>
                    <el-tag type="success" class="gesture">未审核</el-tag>
                </a-space>
            `,
            setup(props: any) {
                return {
                    auditState: props.params.data.auditState,
                    barcodeState: props.params.data.barcodeState
                }
            }
        }
    },
    {
        headerName: '操作',
        field: 'id',
        pinned: 'right',
        width: 150,
        cellRenderer: {
            template: `
            <el-button style="color:#165dff;" @click="a" class="gesture" link>修改</el-button>
            `,
            setup(props: any) {
                const a = () => {
                    // if (props.params.data.stockInTypeName == '织厂送货入库') {
                    editHandler(props.params.data)
                    // } 
                    // else {
                    //     editHandler1(props.params.data)
                    // }

                }
                return {
                    a
                }
            }
        }
    }

];
const tc4 = [
    {
        showRowGroup: 'hide_def',
        "headerName": "",
        "checkboxSelection": true,
        "headerCheckboxSelection": true,
        "pinned": "left",
        "width": 50,
        resizable: false,
        filter: false,
        sortable: false,
        minWidth: 50,
        maxWidth: 50,
        lockPosition: "left",
    },
    {
        headerName: '入库单号',
        field: 'stockInCode',
        width: 150,
    },
    {
        headerName: '入库日期',
        field: 'stockInDate',
        width: 150
    },
    {
        headerName: '收料单号',
        field: 'deliveryCode',
        width: 150
    },
    {
        headerName: '计件日期',
        field: 'reckonPieceDate',
        width: 150
    },
    {
        headerName: '公司',
        field: 'companyName',
        width: 150
    },
    {
        headerName: '仓库',
        field: 'warehouseName',
        width: 150,
    },
    {
        headerName: '业务员',
        field: 'salesman',
        width: 150
    },
    {
        headerName: '入库类型',
        field: 'stockInTypeName',
        width: 150
    },
    {
        headerName: '送货车号',
        field: 'carPlate',
        width: 150
    },
    {
        headerName: '送货工',
        field: 'deliveryPerson',
        width: 150
    },
    {
        headerName: '送货单位',
        field: 'deliveryDepartmentName',
        width: 150,
    },
    {
        headerName: '加工单位',
        field: 'processDepartment',
        width: 150
    },
    {
        headerName: '搬运方式',
        field: 'carryTypeName',
        width: 150
    },
    {
        headerName: '计件方式',
        field: 'reckonPieceTypeName',
        width: 150
    },
    {
        headerName: '备注',
        field: 'remark',
        width: 150
    },
    {
        headerName: '状态',
        field: 'infoState',
        pinned: 'right',
        width: 150,
        cellRenderer: {
            template: `
                <a-space>
                    <el-tag type="success" class="gesture">已审核</el-tag>
                </a-space>
            `,
            setup(props: any) {
                return {
                    auditState: props.params.data.auditState,
                    barcodeState: props.params.data.barcodeState
                }
            }
        }
    },
]
const tc5 = [
    {
        showRowGroup: 'hide_def',
        "headerName": "",
        "checkboxSelection": true,
        "headerCheckboxSelection": true,
        "pinned": "left",
        "width": 50,
        resizable: false,
        filter: false,
        sortable: false,
        minWidth: 50,
        maxWidth: 50,
        lockPosition: "left",
    },
    {
        headerName: '仓库编号',
        field: 'warehouseCode',
        width: 150,
    },
    {
        headerName: '仓库名称',
        field: 'warehouseName',
        width: 150
    },
    {
        headerName: '退库类型',
        field: 'retreatLibraryType',
        width: 150
    },
    {
        headerName: '费用类型',
        field: 'costType',
        width: 150
    },
    {
        headerName: '退库单号',
        field: 'retreatLibraryNum',
        width: 150
    },
    {
        headerName: '开单日期',
        field: 'billingTime',
        width: 150,
    },
    {
        headerName: '客户订单号',
        field: 'clientOrder',
        width: 150
    },
    {
        headerName: '染色单价',
        field: 'dyePrice',
        width: 150
    },
    {
        headerName: '流转卡号',
        field: 'circulationCard',
        width: 150
    },
    {
        headerName: '订单号',
        field: 'orderNo',
        width: 150
    },
    {
        headerName: '计件日期',
        field: 'pieceTime',
        width: 150,
    },
    {
        headerName: '耐氧提升单价',
        field: 'tsprice',
        width: 150
    },
    {
        headerName: '客户名称',
        field: 'clientName',
        width: 150
    },
    {
        headerName: '班组',
        field: 'team',
        width: 150
    },
    {
        headerName: '布号',
        field: 'clothCode',
        width: 150,
    },
    {
        headerName: '重量',
        field: 'weight',
        width: 150
    },
    {
        headerName: '匹数',
        field: 'horsesNum',
        width: 150
    },
    {
        headerName: '送货单位',
        field: 'deliveryDepartmentName',
        width: 150
    },


    {
        headerName: '整理单价',
        field: 'sortPrice',
        width: 150
    },
    {
        headerName: '收费项',
        field: 'chargeItem',
        width: 150,
    },
    {
        headerName: '单价构成',
        field: 'PriceForm',
        width: 150
    },
    {
        headerName: '胶带单价',
        field: 'tapePrice',
        width: 150
    },
    {
        headerName: '抗黄单价',
        field: 'yellowPrice',
        width: 150
    },
    {
        headerName: '纸管单',
        field: 'paperPrice',
        width: 150
    },
    {
        headerName: '备注',
        field: 'remark',
        width: 150
    },
]
const dc5 = [
    {
        showRowGroup: 'hide_def',
        "headerName": "",
        "checkboxSelection": true,
        "headerCheckboxSelection": true,
        "pinned": "left",
        "width": 50,
        resizable: false,
        filter: false,
        sortable: false,
        minWidth: 50,
        maxWidth: 50,
        lockPosition: "left",
    },
    {
        headerName: '坯布编号',
        field: 'greyCode',
        width: 150
    },
    {
        headerName: '坯布名称',
        field: 'greyName',
        width: 150
    },
    {
        headerName: '坯布批号',
        field: 'greyBatchNo',
        width: 150
    },
    {
        headerName: '条码号',
        field: 'clothfiyCode',
        width: 150
    },
    {
        headerName: '品名',
        field: 'brandName',
        width: 150
    },
    {
        headerName: '计划单号',
        field: 'planOrderCode',
        width: 150
    },
    {
        headerName: '原料编号',
        field: 'rawmaterialCode',
        width: 150
    },
    {
        headerName: '原料名称',
        field: 'rawmaterialName',
        width: 150
    },
    {
        headerName: '等级',
        field: 'grade',
        width: 150
    },
    {
        headerName: '匹数',
        field: 'horseNum',
        width: 150
    },
    {
        headerName: '重量',
        field: 'weight',
        width: 150
    },
    {
        headerName: '门幅',
        field: 'width',
        width: 150
    },
    {
        headerName: '纱批',
        field: 'yarnBatch',
        width: 150
    },
    {
        headerName: '单价',
        field: 'price',
        width: 150
    },
    {
        headerName: '金额',
        field: 'amount',
        width: 150
    },
    {
        headerName: '匹号',
        field: 'horseNo',
        width: 150
    },
    {
        headerName: '备注',
        field: 'remark',
        width: 150
    },
    {
        headerName: '库位',
        field: 'storageName',
        dataIndex: 'storageName',
        // pinned: 'right',
        width: 150,
    },
    {
        headerName: '布笼',
        field: 'shelveCode',
        dataIndex: 'shelveCode',
        // pinned: 'right',
        width: 150,
    },
    {
        headerName: '流转卡号',
        field: 'circulatCard',
        width: 150
    },
    {
        headerName: '布号',
        field: 'clothCode',
        width: 150
    },


];
const objectOP = reactive<{
    reckonPieceTypeName: number,
    stocklnDate: any,
    reckonPieceDate: any,
    warehouseName: any,
    warehouseId: any,
    salesman: any,
    stockInTypeName: any,
    customName: any,
    carPlate: any,
    deliveryPerson: any,
    deliveryDepartmentName: any,
    deliveryDepartmentId: any,
    customOrderCode: any,
    processDepartment: any,
    carryTypeName: any,
    horseNum: any,
    weight: any,
    id: any,
    remark: any,
    deliveryCode: any,
    stockInCode: any,
    stockInTypeId: any,
    companyId: any,
    carryTypeId: any,
    BlankStockInDetail: any[],
}>({
    companyId: null,
    stockInTypeId: null,
    reckonPieceTypeName: 0,
    warehouseName: '',
    warehouseId: null,
    id: null,
    stocklnDate: '',
    reckonPieceDate: '',
    salesman: '',
    stockInTypeName: '',
    customName: '',
    carPlate: '',
    deliveryPerson: '',
    deliveryDepartmentName: '',
    deliveryDepartmentId: null,
    customOrderCode: '',
    processDepartment: '',
    carryTypeName: '',
    horseNum: 0,
    weight: 0,
    remark: '',
    deliveryCode: '',
    stockInCode: '',
    carryTypeId: '',
    BlankStockInDetail: [],

});
const pageData = reactive<{
    dutymachineState: any,
    sideTitle: string,
    showAdd8: boolean,
    pageLoading: boolean,
    rHeight: number,
    selsetionPrint: any,
    sourceCode: any,
    supplierName: any,
    customOrderCode: any,
    greyCode: any,
    brandName: any,
    customName: any,
    deliverySourceName: any,
    recordCode: any,
    dateStart: any,
    dateEnd: any,
    nameList: any[],
    nameList1: any[],
    nameList2: any[],
    nameList3: any[],
    nameList4: any[],
    nameListKW: any[],
}>({
    sideTitle: "新增入库单",
    dutymachineState: 0,
    showAdd8: false,
    pageLoading: false,
    rHeight: 0,
    selsetionPrint: '',
    sourceCode: '',
    supplierName: '',
    customOrderCode: '',
    greyCode: '',
    brandName: '',
    customName: '',
    deliverySourceName: '',
    recordCode: '',
    dateStart: '',
    dateEnd: '',
    nameList: [],
    nameList1: [],
    nameList2: [],
    nameList3: [],
    nameList4: [],
    nameListKW: [],
});
// 修改事件
const editHandler = (record: any) => {
    // console.log(record);
    for (var key in record) {
        objectOP[key] = record[key]
    }
    // console.log(objectOP.warehouseName, '1212121121');

    tableDataList1.value = []
    // 明细查询
    let list = gridOption3.value.getSelectedRows().map((item: any) => {
        return { stockInId: item.id }
    })
    post({
        url: "/dwWms/BlankStockInDetail/getList",
        // data: CCobject
        data: list[0]

    }).then((res: any) => {
        if (res.code === 200) {
            tableDataList3_2.value = res.data
        }
    })
    pageData.sideTitle = '修改入库单';
    pageData.showAdd8 = true;

}

const addHandler5 = (ress: any) => {
    if (gridOption5.value.getSelectedRows().length === 0 || gridOption5.value.getSelectedRows().length !== 1) {
        Message.error('勾选数据且只能勾选一条数据')
        return;
    } else {
        pageData.sideTitle = "新增车间退库";
        for (var key in objectOP) {
            if (key == "id") {
                objectOP[key] = null;

            } else {
                objectOP[key] = '';
            }
        }
        objectOP.reckonPieceDate = dayjs().format('YYYY-MM-DD')
        objectOP.stocklnDate = dayjs().format('YYYY-MM-DD')
        tableDataList5_1.value = []
        // 明细查询
        let list = gridOption5.value.getSelectedRows().map((item: any) => {
            return item.id
        })
        post({
            url: "/dwWms/BlankStockIn/getRetreatLibraryDetail",
            // data: CCobject
            data: { retreatLibraryID: list[0] }

        }).then((res: any) => {
            if (res.code === 200) {
                tableDataList5_1.value = res.data
                // console.log(tableDataList1_2.value);

            }
        })
        gridOption5.value.getSelectedRows().map((o: any) => {
            objectOP.stocklnDate = o.billingTime,
                objectOP.reckonPieceDate = o.pieceTime,
                objectOP.warehouseName = o.warehouseName,
                objectOP.warehouseId = o.warehouseId,
                objectOP.salesman = o.createName,
                objectOP.stockInTypeName = "车间退库入库",
                objectOP.customOrderCode = o.clientOrder,
                objectOP.customName = o.clientName,
                objectOP.deliveryDepartmentId = o.deliveryDepartmentId,
                objectOP.deliveryDepartmentName = o.deliveryDepartmentName,
                objectOP.weight = o.weight,
                objectOP.horseNum = o.horsesNum,
                objectOP.remark = o.remark,
                objectOP.deliveryCode = o.retreatLibraryNum,
                objectOP.companyId = o.companyId
            // objectOP.carPlate = o.carPlate,
            // objectOP.deliveryDepartment = o.supplierName,
            // objectOP.processDepartment = o.supplierName,
            // objectOP.weight = o.weight,
            // objectOP.horseNum = o.horseNum,
            // objectOP.deliveryCode = o.sourceCode

        })
        pageData.showAdd8 = true;
    }

}
const selectHandler = () => {
    if (tabsKeys.value == 3) {
        doRefresh3()
    } else if (tabsKeys.value == 4) {
        doRefresh4()
    } else if (tabsKeys.value == 5) {
        doRefresh5()
    }
}
const addHandler = () => {
    if (tabsKeys.value == 5) {
        addHandler5(5)
    }
}

const tabsKeys = ref(5)

const tabsChanges = (e: any) => {
    tabsKeys.value = e
    if (e == 3) {
        toolbarList.value = ['查询', '删除', '审核']
    } else if (e == 4) {
        toolbarList.value = ['查询', '打印']
    } else if (e == 5) {
        toolbarList.value = ['查询', '入库']
    }
}














// 打印事件
const counters = (record: any) => {
    pageData.selsetionPrint = gridOption4.value.getSelectedRows()
    if (pageData.selsetionPrint.length == 0) {
        Message.error({
            content: '请选择您的单据',
            duration: 5000,
        })
        return
    }
    let condition = pageData.selsetionPrint.every(
        (item: any) => item.auditState == 0 || item.auditState == 2
    )
    if (condition) {
        Message.error({
            content: '状态未审核通过不可打印!',
            duration: 5000,
        })
        return
    }
    let ob = pageData.selsetionPrint.map((o: any) => { return o.id })
    post({
        url: '/dwWms/BlankStockIn/getStockInPrintPDF',
        data: ob,
        responseType: 'blob'
    }).then((res) => {
        let reader = new FileReader();
        reader.readAsDataURL(res);
        reader.onload = function () {
            let pdfBase64 = reader.result.replace('data:application/pdf;base64,', '');
            printJS({ printable: pdfBase64, type: 'pdf', base64: true })
        };
    });
}
let stadey: boolean = true
const NO1 = () => {
    stadey = tableDataList1.value.every((item: any) => {
        return item.storageId
    })
}
const NO2 = () => {
    stadey = tableDataList1_2.value.every((item: any) => {
        return item.storageId && item.shelveId
    })
}
const NO3 = () => {
    stadey = tableDataList3_2.value.every((item: any) => {
        return item.storageId
    })
}
// 入库保存事件
const formRef = ref<FormInstance>();
const sideOk = () => {
    if (pageData.sideTitle == "新增织厂送货入库单") {
        NO1()
    } else if (pageData.sideTitle == "新增外加工入库单") {
        NO2()
    } else if (pageData.sideTitle == "修改入库单") {
        NO3()
    } else if (pageData.sideTitle == "新增车间退库") {
        stadey = true
    }
    if (stadey) {

        if (pageData.sideTitle !== '修改入库单') {
            objectOP.stockInCode = objectOP.deliveryCode
            if (objectOP.stockInTypeName === "织厂送货入库") {
                objectOP.stockInTypeId = 40
                tableDataList1.value.forEach((item: any) => {
                    item.id = null
                })
                objectOP.BlankStockInDetail = tableDataList1.value
            } else if (objectOP.stockInTypeName === "外加工入库") {
                objectOP.stockInTypeId = 41
                tableDataList1_2.value.forEach((item: any) => {
                    item.id = null
                })
                objectOP.BlankStockInDetail = tableDataList1_2.value
            } else {
                objectOP.stockInTypeId = 43
                tableDataList5_1.value.forEach((item: any) => {
                    item.id = null
                })
                objectOP.BlankStockInDetail = tableDataList5_1.value
            }
            // if (pageData.sideTitle === "新增织厂送货入库单") {
            post({
                url: "/dwWms/BlankStockIn/insertList",
                data: objectOP
            }).then((res: any) => {
                if (res.code === 200) {
                    formRef.value?.resetFields();
                    pageData.showAdd8 = false;
                    Message.success({
                        content: "新增成功",
                        duration: 5000,
                    });
                    doRefresh5();
                } else {
                    Message.error({
                        content: res.message,
                        duration: 5000,
                    });
                }
            })
        } else {
            objectOP.BlankStockInDetail = tableDataList3_2.value
            post({
                url: "/dwWms/BlankStockIn/updateList",
                data: objectOP
            }).then((res: any) => {
                if (res.code === 200) {
                    formRef.value?.resetFields();
                    pageData.showAdd8 = false;
                    Message.success({
                        content: "修改成功",
                        duration: 5000,
                    });
                    doRefresh3();
                } else {
                    Message.error({
                        content: res.message,
                        duration: 5000,
                    });
                }
            })
        }

    } else {
        Message.error({
            content: '请完整填写库位(不可遗漏)！',
            duration: 5000,
        });
        return
    }

}

const loading = ref(false);

// 业务员下拉框下拉数据
const focusSel1 = () => {
    selCxAll1({ "name": "" });
}
const options1 = ref<any>(pageData.nameList1);
const loading1 = ref(false);
const handleSearch1 = (value: any) => {
    if (value) {
        const ob = { name: value, deleteState: 0 }
        loading1.value = true;
        selCxAll1(ob);
        options1.value = pageData.nameList1;
        loading1.value = false;
    } else {
        options1.value = []
    }
};
function selCxAll1(val: any) {
    post({
        url: "/org/hrEmployee/getList",
        data: val
    }).then(({ data, code }: any) => {
        if (code === 200) {
            pageData.nameList1 = data;
        } else {
            Message.error({
                content: "查询失败！",
                duration: 5000,
            });
        }
    });
}
// 入库类型下拉框下拉数据
const focusSel2 = () => {
    selCxAll2({ "codeType": 29 });
}
const options2 = ref<any>(pageData.nameList2);
const loading2 = ref(false);
const handleSearch2 = (value: any) => {
    if (value) {
        const ob = { codeType: value, deleteState: 0 }
        loading2.value = true;
        selCxAll2(ob);
        options2.value = pageData.nameList2;
        loading2.value = false;
    } else {
        options2.value = []
    }
};
function selCxAll2(val: any) {
    post({
        url: "/dict/dictTypeDetail/getList",
        data: { codeType: 29 }
    }).then(({ data, code }: any) => {
        if (code === 200) {
            pageData.nameList2 = data;
        } else {
            Message.error({
                content: "查询失败！",
                duration: 5000,
            });
        }
    });
}
// 搬运方式下拉框下拉数据
const focusSel4 = () => {
    post({
        url: "dwPc/WarehousePiece/getList",
        data: {}
    }).then(({ data, code }: any) => {
        if (code === 200) {
            pageData.nameList4 = data;
        } else {
            Message.error({
                content: "查询失败！",
                duration: 5000,
            });
        }
    });
}
const change4 = (item: any) => {
    // console.log(item, 'aaaaaaaaaaaaa');
    pageData.nameList4.forEach((o: any) => {
        if (item == o.carryTypeName) {
            objectOP.carryTypeId = o.id
        }
    })
}
// 未审核页面审核方法
const audits = () => {
    if (gridOption3.value.getSelectedRows().length === 0) {
        Message.error('请先勾选')
        return;
    }
    Modal.confirm({
        title: '系统提示',
        content: '是否审核此订单',
        onOk() {
            post({
                url: "/dwWms/BlankStockIn/setAudit",
                // data: auditStateId,
                data: gridOption3.value.getSelectedRows().map((item: any) => {
                    return { id: item.id, auditState: 1 }
                })
            }).then((res: any) => {
                if (res.code === 200) {
                    doRefresh3();
                    Message.success('审核通过')
                    // selectedRowKeys.value = []
                } else {
                    Message.error(res.message)
                }
            })
        }
    })
}
// 删除事件
const deleteHandler = () => {
    if (gridOption3.value.getSelectedRows().length === 0) {
        Message.error('请先勾选')
        return;
    }
    Modal.confirm({
        title: "系统提示",
        content: "确认删除选中的数据?",
        onOk() {
            post({
                url: "/dwWms/BlankStockIn/delete",
                data: gridOption3.value.getSelectedRows().map((o: any) => { return o.id })
            }).then(({ code, data, message }: any) => {
                if (code === 200) {
                    Message.success({
                        content: "删除成功",
                        duration: 5000,
                    });

                    pagination3.page = 1
                    doRefresh3();

                } else {
                    Message.error({
                        content: '删除失败',
                        duration: 5000,
                    });
                }

            });
        },
    });
};
// 织厂收货查询事件
const total3 = ref(10);
const total4 = ref(10);
const total5 = ref(10);
const pagingList1: any = ref(pagingList)

// 未审核查询事件
function doRefresh3() {
    pageData.pageLoading = true
    post({
        url: "/dwWms/BlankStockIn/getPage",
        data: {
            page: pagination3.page,
            size: pagination3.pageSize,
            sourceCode: pageData.sourceCode,
            supplierName: pageData.supplierName,
            customName: pageData.customName,
            dateStart: pageData.dateStart,
            dateEnd: pageData.dateEnd,
            deleteState: 0,
            auditState: 0
        },
    })
        .then(({ data, code }: any) => {
            if (code === 200) {

                table.handleSuccess(data.list);
                gridOption3.value.setRowData(data.list)
                total3.value = data.total;

            }
        })
        .catch(console.log).finally(() => {
            pageData.pageLoading = false
        })
}
// 已审核查询事件
function doRefresh4() {
    pageData.pageLoading = true
    post({
        url: "/dwWms/BlankStockIn/getPage",
        data: {
            page: pagination4.page,
            size: pagination4.pageSize,
            sourceCode: pageData.sourceCode,
            supplierName: pageData.supplierName,
            customName: pageData.customName,
            dateStart: pageData.dateStart,
            dateEnd: pageData.dateEnd,
            deleteState: 0,
            auditState: 1
        },
    })
        .then(({ data, code }: any) => {
            if (code === 200) {

                table.handleSuccess(data.list);
                gridOption4.value.setRowData(data.list)
                total4.value = data.total;

            }
        })
        .catch(console.log).finally(() => {
            pageData.pageLoading = false
        })
}
// 车间退库查询事件
function doRefresh5() {
    pageData.pageLoading = true
    post({
        url: "/dwWms/BlankStockIn/getRetreatLibraryDataLink",
        data: {
            page: pagination5.page,
            size: pagination5.pageSize,
            sourceCode: pageData.sourceCode,
            supplierName: pageData.supplierName,
            customName: pageData.customName,
            dateStart: pageData.dateStart,
            dateEnd: pageData.dateEnd,
            deleteState: 0
        },
    })
        .then(({ data, code }: any) => {
            if (code === 200) {

                table.handleSuccess(data.list);
                gridOption5.value.setRowData(data.list)
                total5.value = data.total;

            }
        })
        .catch(console.log).finally(() => {
            pageData.pageLoading = false
        })
}
const { selectedRowKeys, onSelectionChange } = useRowSelection();
const pagination3 = usePagination(doRefresh3);
const pagination4 = usePagination(doRefresh4);
const pagination5 = usePagination(doRefresh5);
const table = useTable();
const rowKey = useRowKey("id");

const prints2 = () => {
    console.log(gridOption3.value.getSelectedRows());

}
</script>
<script lang="ts">
export default {
    name: "CjTkrukudan",
}
</script>
<style scoped lang="less">
:deep(.ag-cell) {
    border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
    border-right: 1px solid #dde2eb;
}

:deep(.ag-cell-value) {
    user-select: initial;
    -moz-user-select: text;
    -ms-user-select: text;
    -webkit-user-select: text;
}

.DivFit {
    width: 100%;
    height: 20px;
    margin-left: 20px;
}

.DivFit div {
    float: left;
    width: 200px;
}

.isTable1 {
    margin: 50px;
    width: 90%;
    // margin: 0 auto;
    border: 1.2px solid #ccc;
    text-align: center;
    border-collapse: collapse;

    td {
        border: 1.2px solid #ccc;
    }

    th {
        border: 1.2px solid #ccc;
    }
}
</style>
